import {createSelector} from 'reselect';
import {ALL_DEVICE, defaultDeviceListFilter} from "../config/const";

const getAllDeviceList = device => device.deviceList;
const getVisibilityFilter = device => device.deviceListFilter.sort().join('');

const makeGetVisibleDeviceList = () => {
  return createSelector(
    [getVisibilityFilter, getAllDeviceList,],
    (visibilityFilter, deviceList) => {
      // todo fix
      if (visibilityFilter === '') return [];
        //defaultDeviceListFilter  ['1','2','3']
      if (deviceList) {
        return deviceList.data.filter(item => visibilityFilter.includes(item.type.toString()))
      } else {
        return deviceList
      }
    }
  )
};

const getDeviceList = makeGetVisibleDeviceList();
export default getDeviceList
